import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:get/get.dart';

import '../../models/noteModel.dart';

class EditNotePageState {
  ScrollController scrollController = ScrollController();
  ScrollController showScrollController = ScrollController();
  FocusNode contentFocusNode = FocusNode();
  FocusNode titleFocusNode = FocusNode();
  TextEditingController titleController = TextEditingController();
  TextEditingController contentController = TextEditingController();
  late Note note;
  final RxInt contentLength = 0.obs;
  final RxList<File> images = <File>[].obs;
  final RxBool hasChange = false.obs;
  final SwiperController swiperController = SwiperController();
  final RxString showTitle = ''.obs;
  final RxString showData = ''.obs;

  EditNotePageState() {
    ///Initialize variables
    var arg = Get.arguments;
    note = arg ??
        Note(
            id: DateTime.now().toString(),
            createTime: DateTime.now(),
            editTime: DateTime.now());
    titleController.text = note.title;
    contentController.text = note.data;
    for (String imgPath in note.images) {
      images.add(File(imgPath));
    }
    contentLength.value = note.data.length;
    showTitle.value = note.title;
    showData.value = note.data;
  }

  void dispose() {
    contentFocusNode.dispose();
    titleFocusNode.dispose();
    titleController.dispose();
    contentController.dispose();
    scrollController.dispose();
    swiperController.dispose();
    showScrollController.dispose();
  }
}
